package zheezes.protocol.impl.gd;

import java.util.Calendar;

import zheezes.protocol.impl.gd.converter.DateConverter;
import zheezes.util.ByteUtil;


public class Ctrl12Frame extends GdFrame {
    private short option;
    private short start;
    private short amount;
    private Calendar cal = Calendar.getInstance();
    
    public Ctrl12Frame() {
    	ctrl = 0x12;
    }

    public Ctrl12Frame(short option, short start, short amount, Calendar cal) {
        this();
        this.option = option;
        this.start = start;
        this.amount = amount;
        this.cal = cal;
    }

    @Override
    public int sizeOfData() {
    	return 9;
    }
    
    @Override
    public int getData(byte[] buf, int offset) {
    	 int idx = offset;
         ByteUtil.bstoc(buf, idx, option);
         idx += 2;
         ByteUtil.stoc(buf, idx, start);
         idx += 2;
         ByteUtil.stoc(buf, idx, amount);
         idx += 2;
         System.arraycopy(DateConverter.vtob(cal), 0, buf, idx, 3);
         idx+=3;
         
         return idx - offset;
    }

    @Override
    public int setData(byte[] buf, int offset, int max) {
		int idx = offset;
		option = ByteUtil.ctos(buf, idx);
		idx += 2;
		start = ByteUtil.ctos(buf, idx);
		idx += 2;
		amount = ByteUtil.ctos(buf, idx);
		idx += 2;
		byte[] tmp = new byte[3];
		System.arraycopy(buf, idx, tmp, 0, 3);
		cal.setTime(DateConverter.btov(tmp).getTime());

		return idx - offset;
	}

	public short getOption() {
		return option;
	}

	public short getStart() {
		return start;
	}

	public short getAmount() {
		return amount;
	}

	public Calendar getCal() {
		return cal;
	}

	public void setOption(short option) {
		this.option = option;
	}

	public void setStart(short start) {
		this.start = start;
	}

	public void setAmount(short amount) {
		this.amount = amount;
	}

	public void setCal(Calendar cal) {
		this.cal = cal;
	}
}
